#include <bits/stdc++.h>

using namespace std;



struct TreeNode {
    int val;
    TreeNode *left;
    TreeNode *right;
    TreeNode(int x) : val(x), left(NULL), right(NULL) {}
};

class Solution {
    vector<vector<int > > ans;
public:

    void helper(TreeNode* node,vector<int> &v,int tmp,int sum){
        if(node==nullptr) return ;
        tmp+=node->val;
        v.push_back(node->val);
        TreeNode *left=node->left,*right=node->right;
        if(tmp==sum && left==nullptr && right==nullptr){
            ans.push_back(v);
            v.pop_back();
            return;
        }
        //剪支会导致答案错误，不可盲目剪支
        // if(sum>0 && tmp>sum || sum<0 && tmp<sum ){
        //     v.pop_back();
        //     return;
        // }
        helper(left,v,tmp,sum);
        helper(right,v,tmp,sum);

        v.pop_back();

    }

    vector<vector<int>> pathSum(TreeNode* root, int sum) {
        ans.clear();
        vector<int> v; v.clear();
        helper(root,v,0,sum);

        return ans;
    }
};
int main(){




    return 0;
}